package com.qf.servlet;

import com.qf.entity.Classes;
import com.qf.service.ClassesService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 新增学生前 查询班级信息的servlet
 * description:
 * author: Ken
 * 公众号：Java架构栈
 */
@WebServlet(urlPatterns = "/studentinsertquery")
public class StudentInsertQueryServlet extends HttpServlet {

    private ClassesService classesService = new ClassesService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //查询所有班级信息
        List<Classes> classes = classesService.queryCls();

        if (classes.size() == 0) {
            //说明没有班级
            resp.sendRedirect("stuinserterror.jsp");
            return;
        }

        req.setAttribute("classes", classes);
        //转发给学生新增页面
        req.getRequestDispatcher("stuinsert.jsp").forward(req, resp);
    }
}
